package com.libl.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

public class MybatisConfig {

    @Bean//替换xml配置文件中创建sqlSessionFactory工厂对象的bean标签
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource){
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();

        sqlSessionFactoryBean.setDataSource(dataSource);//设置property属性，传入数据源连接池
        sqlSessionFactoryBean.setTypeAliasesPackage("com.libl.domain");//设置property属性，按包配置别名
        //sqlSessionFactoryBean.setConfiguration(); 开启驼峰命名怎么配？？

        return sqlSessionFactoryBean;
    }

    @Bean//替换xml配置文件中创建包扫描器的bean标签
    public MapperScannerConfigurer mapperScannerConfigurer(){
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setBasePackage("com.libl.mapper");//设置property属性，传入要扫描的包

        return mapperScannerConfigurer;
    }
}
